package com.example.wacoffee_user.service.Impl;


import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wacoffee_user.mapper.CartMapper;
import com.example.wacoffee_user.pojo.entity.Good;
import com.example.wacoffee_user.service.ICartService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.List;

@Service
public class CartServiceImpl extends ServiceImpl<CartMapper, Good> implements ICartService {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public List<Good> getAllGoods() {
        String strJson = stringRedisTemplate.opsForValue().get("goods");
        if (strJson != null) {
            JSONArray objects = JSONUtil.parseArray(strJson);
            return JSONUtil.toList(objects, Good.class);
        }
        return list();
    }
}
